package com.company.creational.factory_pattern.simple_factory_pattern.factory;

import com.company.creational.factory_pattern.simple_factory_pattern.product.Chart;
import com.company.creational.factory_pattern.simple_factory_pattern.product.HistogramChart;
import com.company.creational.factory_pattern.simple_factory_pattern.product.LineChart;
import com.company.creational.factory_pattern.simple_factory_pattern.product.PieChart;

/**
 * @ClassName ChartFactory
 * @Author tiezheng.han
 * @Date 2020/8/26 17:44
 **/
public class ChartFactory {

    private static final String HISTOGRAM = "histogram";
    private static final String PIE = "pie";
    private static final String LINE = "line";

    /**
     * 静态工厂方法
     */
    public static Chart getChart(String type){
        Chart chart = null;
        if (type.equalsIgnoreCase(HISTOGRAM)){
            chart = new HistogramChart();
            System.out.println("初始化设置柱状图！");
        } else if (type.equalsIgnoreCase(PIE)){
            chart = new PieChart();
            System.out.println("初始化设置饼状图！");
        } else if (type.equalsIgnoreCase(LINE)){
            chart = new LineChart();
            System.out.println("初始化设置折线图！");
        }
        return chart;
    }
}
